home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility2 / wine02bx.zip / INFO / EMACS.5 < prev    next >
Text File  |  1993-03-28  |  46KB  |  1,091 lines

  1. Info file ../info/emacs, produced by Makeinfo, -*- Text -*- from input
  2. file lemacs.tex.
  3.  
  4.    This file documents the GNU Emacs editor.
  5.  
  6.    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.  Copyright (C)
  7. 1991, 1992 Lucid, Inc.
  8.  
  9.    Permission is granted to make and distribute verbatim copies of
  10. this manual provided the copyright notice and this permission notice
  11. are preserved on all copies.
  12.  
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided also
  15. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  16. General Public License" are included exactly as in the original, and
  17. provided that the entire resulting derived work is distributed under
  18. the terms of a permission notice identical to this one.
  19.  
  20.    Permission is granted to copy and distribute translations of this
  21. manual into another language, under the above conditions for modified
  22. versions, except that the sections entitled "The GNU Manifesto",
  23. "Distribution" and "GNU General Public License" may be included in a
  24. translation approved by the author instead of in the original English.
  25.  
  26. 
  27. File: emacs,  Node: Incremental Search,  Next: Non-Incremental Search,  Prev: Search,  Up: Search
  28.  
  29. Incremental Search
  30. ==================
  31.  
  32.    An incremental search begins searching as soon as you type the first
  33. character of the search string.  As you type in the search string,
  34. Emacs shows you where the string (as you have typed it so far) is
  35. found.  When you have typed enough characters to identify the place
  36. you want, you can stop.  Depending on what you do next, you may or may
  37. not need to terminate the search explicitly with a RET.
  38.  
  39. `C-s'
  40.      Incremental search forward (`isearch-forward').
  41.  
  42. `C-r'
  43.      Incremental search backward (`isearch-backward').
  44.  
  45.    `C-s' starts an incremental search.  `C-s' reads characters from
  46. the keyboard and positions the cursor at the first occurrence of the
  47. characters that you have typed.  If you type `C-s' and then `F', the
  48. cursor moves right after the first `F'.  Type an `O', and see the
  49. cursor move to after the first `FO'.  After another `O', the cursor is
  50. after the first `FOO' after the place where you started the search. 
  51. Meanwhile, the search string `FOO' has been echoed in the echo area.
  52.  
  53.    The echo area display ends with three dots when actual searching is
  54. going on.  When search is waiting for more input, the three dots are
  55. removed.  (On slow terminals, the three dots are not displayed.)
  56.  
  57.    If you make a mistake in typing the search string, you can erase
  58. characters with DEL.  Each DEL cancels the last character of the
  59. search string.  This does not happen until Emacs is ready to read
  60. another input character; first it must either find, or fail to find,
  61. the character you want to erase.  If you do not want to wait for this
  62. to happen, use `C-g' as described below.
  63.  
  64.    When you are satisfied with the place you have reached, you can type
  65. RET (or C-m), which stops searching, leaving the cursor where the
  66. search brought it.  Any command not specially meaningful in searches
  67. also stops the search and is then executed.  Thus, typing `C-a' exits
  68. the search and then moves to the beginning of the line.  RET is
  69. necessary only if the next command you want to type is a printing
  70. character, DEL, ESC, or another control character that is special
  71. within searches (`C-q', `C-w', `C-r', `C-s' or `C-y').
  72.  
  73.    Sometimes you search for `FOO' and find it, but were actually
  74. looking for a different occurance of it.  To move to the next
  75. occurrence of the search string, type another `C-s'.  Do this as often
  76. as necessary.  If you overshoot, you can cancel some `C-s' characters
  77. with DEL.
  78.  
  79.    After you exit a search, you can search for the same string again by
  80. typing just `C-s C-s': the first `C-s' is the key that invokes
  81. incremental search, and the second `C-s' means "search again".
  82.  
  83.    If the specified string is not found at all, the echo area displays
  84. the text `Failing I-Search'.  The cursor is after the place where
  85. Emacs found as much of your string as it could.  Thus, if you search
  86. for `FOOT', and there is no `FOOT', the cursor may be after the `FOO'
  87. in `FOOL'.  At this point there are several things you can do.  If you
  88. mistyped the search string, correct it.  If you like the place you
  89. have found, you can type RET or some other Emacs command to "accept
  90. what the search offered".  Or you can type `C-g', which removes from
  91. the search string the characters that could not be found (the `T' in
  92. `FOOT'), leaving those that were found (the `FOO' in `FOOT').  A
  93. second `C-g' at that point cancels the search entirely, returning
  94. point to where it was when the search started.
  95.  
  96.    If a search is failing and you ask to repeat it by typing another
  97. `C-s', it starts again from the beginning of the buffer.  Repeating a
  98. failing reverse search with `C-r' starts again from the end.  This is
  99. called "wrapping around".  `Wrapped' appears in the search prompt once
  100. this has happened.
  101.  
  102.    The `C-g' "quit" character does special things during searches;
  103. just what it does depends on the status of the search.  If the search
  104. has found what you specified and is waiting for input, `C-g' cancels
  105. the entire search.  The cursor moves back to where you started the
  106. search.  If `C-g' is typed when there are characters in the search
  107. string that have not been found--because Emacs is still searching for
  108. them, or because it has failed to find them--then the search string
  109. characters which have not been found are discarded from the search
  110. string.  The search is now successful and waiting for more input, so a
  111. second `C-g' cancels the entire search.
  112.  
  113.    To search for a control character such as `C-s' or DEL or ESC, you
  114. must quote it by typing `C-q' first.  This function of `C-q' is
  115. analogous to its meaning as an Emacs command: it causes the following
  116. character to be treated the way a graphic character would normally be
  117. treated in the same context.
  118.  
  119.    To search backwards, you can use `C-r' instead of `C-s' to start
  120. the search; `C-r' is the key that runs the command
  121. (`isearch-backward') to search backward.  You can also use `C-r' to
  122. change from searching forward to searching backwards.  Do this if a
  123. search fails because the place you started was too far down in the
  124. file.  Repeated `C-r' keeps looking for more occurrences backwards. 
  125. `C-s' starts going forward again.  You can cancel `C-r' in a search
  126. with DEL.
  127.  
  128.    The characters `C-y' and `C-w' can be used in incremental search to
  129. grab text from the buffer into the search string.  This makes it
  130. convenient to search for another occurrence of text at point.  `C-w'
  131. copies the word after point as part of the search string, advancing
  132. point over that word.  Another `C-s' to repeat the search will then
  133. search for a string including that word.  `C-y' is similar to `C-w'
  134. but copies the rest of the current line into the search string.
  135.  
  136.    The characters `M-p' and `M-n' can be used in an incremental search
  137. to recall things which you have searched for in the past.  A list of
  138. the last 16 things you have searched for is retained, and `M-p' and
  139. `M-n' let you cycle through that ring.
  140.  
  141.    The character `M-TAB' does completion on the elements in the search
  142. history ring.  For example, if you know that you have recently
  143. searched for the string `POTATOE', you could type `C-s P O M-TAB'.  If
  144. you had searched for other strings beginning with `PO' then you would
  145. be shown a list of them, and would need to type more to select one.
  146.  
  147.    You can change any of the special characters in incremental search
  148. via the normal keybinding mechanism: simply add a binding to the
  149. `isearch-mode-map'.  For example, to make the character `C-b' mean
  150. "search backwards" while in isearch-mode, do this:
  151.  
  152.      (define-key isearch-mode-map "\C-b" 'isearch-repeat-backward)
  153.  
  154.    These are the default bindings of isearch-mode:
  155.  
  156. `DEL'
  157.      (`isearch-delete-char')  Delete a character from the incremental
  158.      search string.
  159.  
  160. `RET'
  161.      (`isearch-exit')  Exit incremental search.
  162.  
  163. `C-q'
  164.      (`isearch-quote-char')  Quote special characters for incremental
  165.      search.
  166.  
  167. `C-s'
  168.      (`isearch-repeat-forward')  Repeat incremental search forward.
  169.  
  170. `C-r'
  171.      (`isearch-repeat-reverse')  Repeat incremental search backward.
  172.  
  173. `C-y'
  174.      (`isearch-yank-line')  Pull rest of line from buffer into search
  175.      string.
  176.  
  177. `C-w'
  178.      (`isearch-yank-word')  Pull next word from buffer into search
  179.      string.
  180.  
  181. `C-g'
  182.      (`isearch-abort')  Cancels input back to what has been found
  183.      successfully, or aborts the isearch.
  184.  
  185. `M-p'
  186.      (`isearch-ring-retreat')  Recall the previous element in the
  187.      isearch history ring.
  188.  
  189. `M-n'
  190.      (`isearch-ring-advance')  Recall the next element in the isearch
  191.      history ring.
  192.  
  193. `M-TAB'
  194.      (`isearch-complete')  Do completion on the elements in the isearch
  195.      history ring.
  196.  
  197.    Any other character which is normally inserted into a buffer when
  198. typed is automatically added to the search string in isearch-mode.
  199.  
  200. Slow Terminal Incremental Search
  201. --------------------------------
  202.  
  203.    Incremental search on a slow terminal uses a modified style of
  204. display that is designed to take less time.  Instead of redisplaying
  205. the buffer at each place the search gets to, it creates a new
  206. single-line window and uses that to display the line the search has
  207. found.  The single-line window appears as soon as point gets outside
  208. of the text that is already on the screen.
  209.  
  210.    When the search is terminated, the single-line window is removed. 
  211. Only at this time the window in which the search was done is
  212. redisplayed to show its new value of point.
  213.  
  214.    The three dots at the end of the search string, normally used to
  215. indicate that searching is going on, are not displayed in slow style
  216. display.
  217.  
  218.    The slow terminal style of display is used when the terminal baud
  219. rate is less than or equal to the value of the variable
  220. `search-slow-speed', initially 1200.
  221.  
  222.    The number of lines to use in slow terminal search display is
  223. controlled by the variable `search-slow-window-lines'.  Its normal
  224. value is 1.
  225.  
  226. 
  227. File: emacs,  Node: Non-Incremental Search,  Next: Word Search,  Prev: Incremental Search,  Up: Search
  228.  
  229. Non-Incremental Search
  230. ======================
  231.  
  232.    Emacs also has conventional non-incremental search commands, which
  233. require you type the entire search string before searching begins.
  234.  
  235. `C-s RET STRING RET'
  236.      Search for STRING.
  237.  
  238. `C-r RET STRING RET'
  239.      Search backward for STRING.
  240.  
  241.    To do a non-incremental search, first type `C-s RET' (or `C-s C-m'.
  242.  This enters the minibuffer to read the search string.  Terminate the
  243. string with RET to start the search.  If the string is not found the
  244. search command gets an error.
  245.  
  246.    By default, `C-s' invokes incremental search, but if you give it an
  247. empty argument, which would otherwise be useless, it invokes
  248. non-incremental search.  Therefore, `C-s RET' invokes non-incremental
  249. search.  `C-r RET' also works this way.
  250.  
  251.    Forward and backward non-incremental searches are implemented by the
  252. commands `search-forward' and `search-backward'.  You can bind these
  253. commands to keys.  The reason that incremental search is programmed to
  254. invoke them as well is that `C-s RET' is the traditional sequence of
  255. characters used in Emacs to invoke non-incremental search.
  256.  
  257.    Non-Incremental searches performed using `C-s RET' do not call
  258. `search-forward' right away.  They first check if the next character
  259. is `C-w', which requests a word search.
  260.  
  261.    *Note Word Search::.
  262.  
  263. 
  264. File: emacs,  Node: Word Search,  Next: Regexp Search,  Prev: Non-Incremental Search,  Up: Search
  265.  
  266. Word Search
  267. ===========
  268.  
  269.    Word search looks for a sequence of words without regard to how the
  270. words are separated.  More precisely, you type a string of many words,
  271. using single spaces to separate them, and the string is found even if
  272. there are multiple spaces, newlines or other punctuation between the
  273. words.
  274.  
  275.    Word search is useful in editing documents formatted by text
  276. formatters.  If you edit while looking at the printed, formatted
  277. version, you can't tell where the line breaks are in the source file. 
  278. Word search, allows you to search  without having to know the line
  279. breaks.
  280.  
  281. `C-s RET C-w WORDS RET'
  282.      Search for WORDS, ignoring differences in punctuation.
  283.  
  284. `C-r RET C-w WORDS RET'
  285.      Search backward for WORDS, ignoring differences in punctuation.
  286.  
  287.    Word search is a special case of non-incremental search.  It is
  288. invoked with `C-s RET C-w' followed by the search string, which must
  289. always be terminated with another RET.  Being non-incremental, this
  290. search does not start until the argument is terminated.  It works by
  291. constructing a regular expression and searching for that.  *Note
  292. Regexp Search::.
  293.  
  294.    You can do a backward word search with `C-r RET C-w'.
  295.  
  296.    Forward and backward word searches are implemented by the commands
  297. `word-search-forward' and `word-search-backward'.  You can bind these
  298. commands to keys.  The reason that incremental search is programmed to
  299. invoke them as well is that `C-s RET C-w' is the traditional Emacs
  300. sequence of keys for word search.
  301.  
  302. 
  303. File: emacs,  Node: Regexp Search,  Next: Regexps,  Prev: Word Search,  Up: Search
  304.  
  305. Regular Expression Search
  306. =========================
  307.  
  308.    A "regular expression" ("regexp", for short) is a pattern that
  309. denotes a set of strings, possibly an infinite set.  Searching for
  310. matches for a regexp is a powerful operation that editors on Unix
  311. systems have traditionally offered.  In GNU Emacs, you can search for
  312. the next match for a regexp either incrementally or not.
  313.  
  314.    Incremental search for a regexp is done by typing `C-M-s'
  315. (`isearch-forward-regexp').  This command reads a search string
  316. incrementally just like `C-s', but it treats the search string as a
  317. regexp rather than looking for an exact match against the text in the
  318. buffer.  Each time you add text to the search string, you make the
  319. regexp longer, and the new regexp is searched for.  A reverse regexp
  320. search command `isearch-backward-regexp' also exists but no key runs
  321. it.
  322.  
  323.    All of the control characters that do special things within an
  324. ordinary incremental search have the same functionality in incremental
  325. regexp search.  Typing `C-s' or `C-r' immediately after starting a
  326. search retrieves the last incremental search regexp used: incremental
  327. regexp and non-regexp searches have independent defaults.
  328.  
  329.    Non-Incremental search for a regexp is done by the functions
  330. `re-search-forward' and `re-search-backward'.  You can invoke them
  331. with `M-x' or bind them to keys.  You can also call
  332. `re-search-forward' by way of incremental regexp search with `C-M-s
  333. RET'.
  334.  
  335. 
  336. File: emacs,  Node: Regexps,  Next: Search Case,  Prev: Regexp Search,  Up: Search
  337.  
  338. Syntax of Regular Expressions
  339. =============================
  340.  
  341.    Regular expressions have a syntax in which a few characters are
  342. special constructs and the rest are "ordinary".  An ordinary character
  343. is a simple regular expression which matches that character and
  344. nothing else.  The special characters are `$', `^', `.', `*', `+',
  345. `?', `[', `]' and `\'; no new special characters will be defined.  Any
  346. other character appearing in a regular expression is ordinary, unless
  347. a `\' precedes it.
  348.  
  349.    For example, `f' is not a special character, so it is ordinary, and
  350. therefore `f' is a regular expression that matches the string `f' and
  351. no other string.  (It does not match the string `ff'.)  Likewise, `o'
  352. is a regular expression that matches only `o'.
  353.  
  354.    Any two regular expressions A and B can be concatenated.  The
  355. result is a regular expression which matches a string if A matches
  356. some amount of the beginning of that string and B matches the rest of
  357. the string.
  358.  
  359.    As a simple example, you can concatenate the regular expressions `f'
  360. and `o' to get the regular expression `fo', which matches only the
  361. string `fo'.  To do something nontrivial, you need to use one of the
  362. following special characters:
  363.  
  364. `. (Period)'
  365.      is a special character that matches any single character except a
  366.      newline.  Using concatenation, you can make regular expressions
  367.      like `a.b' which matches any three-character string which begins
  368.      with `a' and ends with `b'.
  369.  
  370. `*'
  371.      is not a construct by itself; it is a suffix, which means the
  372.      preceding regular expression is to be repeated as many times as
  373.      possible.  In `fo*', the `*' applies to the `o', so `fo*' matches
  374.      one `f' followed by any number of `o's.  The case of zero `o's is
  375.      allowed: `fo*' does match `f'.
  376.  
  377.      `*' always applies to the smallest possible preceding expression.
  378.       Thus, `fo*' has a repeating `o', not a repeating `fo'.
  379.  
  380.      The matcher processes a `*' construct by matching, immediately,
  381.      as many repetitions as it can find.  Then it continues with the
  382.      rest of the pattern.  If that fails, backtracking occurs,
  383.      discarding some of the matches of the `*'-modified construct in
  384.      case that makes it possible to match the rest of the pattern. 
  385.      For example, matching `ca*ar' against the string `caaar', the
  386.      `a*' first tries to match all three `a's; but the rest of the
  387.      pattern is `ar' and there is only `r' left to match, so this try
  388.      fails.  The next alternative is for `a*' to match only two `a's. 
  389.      With this choice, the rest of the regexp matches successfully.
  390.  
  391. `+'
  392.      Is a suffix character similar to `*' except that it requires that
  393.      the preceding expression be matched at least once.  For example,
  394.      `ca+r' will match the strings `car' and `caaaar' but not the
  395.      string `cr', whereas `ca*r' would match all three strings.
  396.  
  397. `?'
  398.      Is a suffix character similar to `*' except that it can match the
  399.      preceding expression either once or not at all.  For example,
  400.      `ca?r' will match `car' or `cr'; nothing else.
  401.  
  402. `[ ... ]'
  403.      `[' begins a "character set", which is terminated by a `]'.  In
  404.      the simplest case, the characters between the two form the set. 
  405.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  406.      matches any string composed of just `a's and `d's (including the
  407.      empty string), from which it follows that `c[ad]*r' matches `cr',
  408.      `car', `cdr', `caddaar', etc.
  409.  
  410.      You can include character ranges in a character set by writing
  411.      two characters with a `-' between them.  Thus, `[a-z]' matches
  412.      any lower-case letter.  Ranges may be intermixed freely with
  413.      individual characters, as in `[a-z$%.]', which matches any lower
  414.      case letter or `$', `%' or period.
  415.  
  416.      Note that inside a character set the usual special characters are
  417.      not special any more.  A completely different set of special
  418.      characters exists inside character sets: `]', `-' and `^'.
  419.  
  420.      To include a `]' in a character set, you must make it the first
  421.      character.  For example, `[]a]' matches `]' or `a'.  To include a
  422.      `-', write `--', which is a range containing only `-'.  To
  423.      include `^', make it other than the first character in the set.
  424.  
  425. `[^ ... ]'
  426.      `[^' begins a "complement character set", which matches any
  427.      character except the ones specified.  Thus, `[^a-z0-9A-Z]'
  428.      matches all characters except letters and digits.
  429.  
  430.      `^' is not special in a character set unless it is the first
  431.      character.  The character following the `^' is treated as if it
  432.      were first (`-' and `]' are not special there).
  433.  
  434.      Note that a complement character set can match a newline, unless
  435.      newline is mentioned as one of the characters not to match.
  436.  
  437. `^'
  438.      is a special character that matches the empty string, but only if
  439.      at the beginning of a line in the text being matched.  Otherwise,
  440.      it fails to match anything.  Thus, `^foo' matches a `foo' that
  441.      occurs at the beginning of a line.
  442.  
  443. `$'
  444.      is similar to `^' but matches only at the end of a line.  Thus,
  445.      `xx*$' matches a string of one `x' or more at the end of a line.
  446.  
  447. `\'
  448.      does two things: it quotes the special characters (including
  449.      `\'), and it introduces additional special constructs.
  450.  
  451.      Because `\' quotes special characters, `\$' is a regular
  452.      expression that matches only `$', and `\[' is a regular
  453.      expression that matches only `[', and so on.
  454.  
  455.    Note: for historical compatibility, special characters are treated
  456. as ordinary ones if they are in contexts where their special meanings
  457. make no sense.  For example, `*foo' treats `*' as ordinary since there
  458. is no preceding expression on which the `*' can act.  It is poor
  459. practice to depend on this behavior; better to quote the special
  460. character anyway, regardless of where is appears.
  461.  
  462.    Usually, `\' followed by any character matches only that character.
  463.  However, there are several exceptions: characters which, when
  464. preceded by `\', are special constructs.  Such characters are always
  465. ordinary when encountered on their own.  Here is a table of `\'
  466. constructs.
  467.  
  468. `\|'
  469.      specifies an alternative.  Two regular expressions A and B with
  470.      `\|' in between form an expression that matches anything A or B
  471.      matches.
  472.  
  473.      Thus, `foo\|bar' matches either `foo' or `bar' but no other
  474.      string.
  475.  
  476.      `\|' applies to the largest possible surrounding expressions. 
  477.      Only a surrounding `\( ... \)' grouping can limit the grouping
  478.      power of `\|'.
  479.  
  480.      Full backtracking capability exists to handle multiple uses of
  481.      `\|'.
  482.  
  483. `\( ... \)'
  484.      is a grouping construct that serves three purposes:
  485.  
  486.        1. To enclose a set of `\|' alternatives for other operations. 
  487.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  488.  
  489.        2. To enclose a complicated expression for the postfix `*' to
  490.           operate on.  Thus, `ba\(na\)*' matches `bananana', etc.,
  491.           with any (zero or more) number of `na' strings.
  492.  
  493.        3. To mark a matched substring for future reference.
  494.  
  495.           This last application is not a consequence of the idea of a
  496.      parenthetical grouping; it is a separate feature which happens to
  497.      be assigned as a second meaning to the same `\( ... \)' construct
  498.      because in practice there is no conflict between the two meanings. 
  499.      Here is an explanation:
  500.  
  501. `\DIGIT'
  502.      after the end of a `\( ... \)' construct, the matcher remembers
  503.      the beginning and end of the text matched by that construct. 
  504.      Then, later on in the regular expression, you can use `\'
  505.      followed by DIGIT to mean "match the same text matched the
  506.      DIGIT'th time by the `\( ... \)' construct."
  507.  
  508.      The strings matching the first nine `\( ... \)' constructs
  509.      appearing in a regular expression are assigned numbers 1 through
  510.      9 in order that the open-parentheses appear in the regular
  511.      expression.  `\1' through `\9' may be used to refer to the text
  512.      matched by the corresponding `\( ... \)' construct.
  513.  
  514.      For example, `\(.*\)\1' matches any newline-free string that is
  515.      composed of two identical halves.  The `\(.*\)' matches the first
  516.      half, which may be anything, but the `\1' that follows must match
  517.      the same exact text.
  518.  
  519. `\`'
  520.      matches the empty string, provided it is at the beginning of the
  521.      buffer.
  522.  
  523. `\''
  524.      matches the empty string, provided it is at the end of the buffer.
  525.  
  526. `\b'
  527.      matches the empty string, provided it is at the beginning or end
  528.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  529.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  530.      separate word.
  531.  
  532. `\B'
  533.      matches the empty string, provided it is not at the beginning or
  534.      end of a word.
  535.  
  536. `\<'
  537.      matches the empty string, provided it is at the beginning of a
  538.      word.
  539.  
  540. `\>'
  541.      matches the empty string, provided it is at the end of a word.
  542.  
  543. `\w'
  544.      matches any word-constituent character.  The editor syntax table
  545.      determines which characters these are.
  546.  
  547. `\W'
  548.      matches any character that is not a word-constituent.
  549.  
  550. `\sCODE'
  551.      matches any character whose syntax is CODE.  CODE is a character
  552.      which represents a syntax code: thus, `w' for word constituent,
  553.      `-' for whitespace, `(' for open-parenthesis, etc.  *Note
  554.      Syntax::.
  555.  
  556. `\SCODE'
  557.      matches any character whose syntax is not CODE.
  558.  
  559.    Here is a complicated regexp, used by Emacs to recognize the end of
  560. a sentence together with any whitespace that follows.  It is given in
  561. Lisp syntax to enable you to distinguish the spaces from the tab
  562. characters.  In Lisp syntax, the string constant begins and ends with
  563. a double-quote.  `\"' stands for a double-quote as part of the regexp,
  564. `\\' for a backslash as part of the regexp, `\t' for a tab and `\n'
  565. for a newline.
  566.  
  567.      "[.?!][]\"')]*\\($\\|\t\\|  \\)[ \t\n]*"
  568.  
  569. This regexp contains four parts: a character set matching period, `?'
  570. or `!'; a character set matching close-brackets, quotes or
  571. parentheses, repeated any number of times; an alternative in
  572. backslash-parentheses that matches end-of-line, a tab or two spaces;
  573. and a character set matching whitespace characters, repeated any
  574. number of times.
  575.  
  576. 
  577. File: emacs,  Node: Search Case,  Next: Replace,  Prev: Regexps,  Up: Search
  578.  
  579. Searching and Case
  580. ==================
  581.  
  582.    All searches in Emacs normally ignore the case of the text they are
  583. searching through; if you specify searching for `FOO', `Foo' and `foo'
  584. are also considered a match.  Regexps, and in particular character
  585. sets, are included: `[aB]' matches `a' or `A' or `b' or `B'.
  586.  
  587.    If you want a case-sensitive search, set the variable
  588. `case-fold-search' to `nil'.  Then all letters must match exactly,
  589. including case. `case-fold-search' is a per-buffer variable; altering
  590. it affects only the current buffer, but there is a default value which
  591. you can change as well.  *Note Locals::.
  592.  
  593. 
  594. File: emacs,  Node: Replace,  Next: Other Repeating Search,  Prev: Search Case,  Up: Search
  595.  
  596. Replacement Commands
  597. ====================
  598.  
  599.    Global search-and-replace operations are not needed as often in
  600. Emacs as they are in other editors, but they are available.  In
  601. addition to the simple `replace-string' command which is like that
  602. found in most editors, there is a `query-replace' command which asks
  603. you, for each occurrence of a pattern, whether to replace it.
  604.  
  605.    The replace commands all replace one string (or regexp) with one
  606. replacement string.  It is possible to perform several replacements in
  607. parallel using the command `expand-region-abbrevs'.  *Note Expanding
  608. Abbrevs::.
  609.  
  610. * Menu:
  611.  
  612. * Unconditional Replace::  Replacing all matches for a string.
  613. * Regexp Replace::         Replacing all matches for a regexp.
  614. * Replacement and Case::   How replacements preserve case of letters.
  615. * Query Replace::          How to use querying.
  616.  
  617. 
  618. File: emacs,  Node: Unconditional Replace,  Next: Regexp Replace,  Prev: Replace,  Up: Replace
  619.  
  620. Unconditional Replacement
  621. -------------------------
  622.  
  623. `M-x replace-string RET STRING RET NEWSTRING RET'
  624.      Replace every occurrence of STRING with NEWSTRING.
  625.  
  626. `M-x replace-regexp RET REGEXP RET NEWSTRING RET'
  627.      Replace every match for REGEXP with NEWSTRING.
  628.  
  629.    To replace every instance of `foo' after point with `bar', use the
  630. command `M-x replace-string' with the two arguments `foo' and `bar'. 
  631. Replacement occurs only after point: if you want to cover the whole
  632. buffer you must go to the beginning first.  By default, all
  633. occurrences up to the end of the buffer are replaced.  To limit
  634. replacement to part of the buffer, narrow to that part of the buffer
  635. before doing the replacement (*note Narrowing::.).
  636.  
  637.    When `replace-string' exits, point is left at the last occurrence
  638. replaced.  The value of point when the `replace-string' command was
  639. issued is remembered on the mark ring; `C-u C-SPC' moves back there.
  640.  
  641.    A numeric argument restricts replacement to matches that are
  642. surrounded by word boundaries.
  643.  
  644. 
  645. File: emacs,  Node: Regexp Replace,  Next: Replacement and Case,  Prev: Unconditional Replace,  Up: Replace
  646.  
  647. Regexp Replacement
  648. ------------------
  649.  
  650.    `replace-string' replaces exact matches for a single string.  The
  651. similar command `replace-regexp' replaces any match for a specified
  652. pattern.
  653.  
  654.    In `replace-regexp', the NEWSTRING need not be constant.  It can
  655. refer to all or part of what is matched by the REGEXP.  `\&' in
  656. NEWSTRING stands for the entire text being replaced.  `\D' in
  657. NEWSTRING, where D is a digit, stands for whatever matched the D'th
  658. parenthesized grouping in REGEXP.  For example,
  659.  
  660.      M-x replace-regexp RET c[ad]+r RET \&-safe RET
  661.  
  662. would replace (for example) `cadr' with `cadr-safe' and `cddr' with
  663. `cddr-safe'.
  664.  
  665.      M-x replace-regexp RET \(c[ad]+r\)-safe RET \1 RET
  666.  
  667. would perform exactly the opposite replacements.  To include a `\' in
  668. the text to replace with, you must give `\\'.
  669.  
  670. 
  671. File: emacs,  Node: Replacement and Case,  Next: Query Replace,  Prev: Regexp Replace,  Up: Replace
  672.  
  673. Replace Commands and Case
  674. -------------------------
  675.  
  676.    If the arguments to a replace command are in lower case, the command
  677. preserves case when it makes a replacement.  Thus, the command
  678.  
  679.      M-x replace-string RET foo RET bar RET
  680.  
  681. replaces a lower case `foo' with a lower case `bar', `FOO' with `BAR',
  682. and `Foo' with `Bar'.  If upper case letters are used in the second
  683. argument, they remain upper case every time that argument is inserted.
  684.  If upper case letters are used in the first argument, the second
  685. argument is always substituted exactly as given, with no case
  686. conversion.  Likewise, if the variable `case-replace' is set to `nil',
  687. replacement is done without case conversion.  If `case-fold-search' is
  688. set to `nil', case is significant in matching occurrences of `foo' to
  689. replace; also, case conversion of the replacement string is not done.
  690.  
  691. 
  692. File: emacs,  Node: Query Replace,  Prev: Replacement and Case,  Up: Replace
  693.  
  694. Query Replace
  695. -------------
  696.  
  697. `M-% STRING RET NEWSTRING RET'
  698. `M-x query-replace RET STRING RET NEWSTRING RET'
  699.      Replace some occurrences of STRING with NEWSTRING.
  700.  
  701. `M-x query-replace-regexp RET REGEXP RET NEWSTRING RET'
  702.      Replace some matches for REGEXP with NEWSTRING.
  703.  
  704.    If you want to change only some of the occurrences of `foo' to
  705. `bar', not all of them, you can (`query-replace') instead of `M-%'. 
  706. This command finds occurrences of `foo' one by one, displays each
  707. occurrence, and asks you whether to replace it.  A numeric argument to
  708. `query-replace' tells it to consider only occurrences that are bounded
  709. by word-delimiter characters.
  710.  
  711.    Aside from querying, `query-replace' works just like
  712. `replace-string', and `query-replace-regexp' works just like
  713. `replace-regexp'.
  714.  
  715.    The things you can type when you are shown an occurrence of STRING
  716. or a match for REGEXP are:
  717.  
  718. `SPC'
  719.      to replace the occurrence with NEWSTRING.  This preserves case,
  720.      just like `replace-string', provided `case-replace' is non-`nil',
  721.      as it normally is.
  722.  
  723. `DEL'
  724.      to skip to the next occurrence without replacing this one.
  725.  
  726. `, (Comma)'
  727.      to replace this occurrence and display the result.  You are then
  728.      prompted for another input character, however, since the
  729.      replacement has already been made, DEL and SPC are equivalent. 
  730.      At this point, you can type `C-r' (see below) to alter the
  731.      replaced text.  To undo the replacement, you can type `C-x u'. 
  732.      This exits the `query-replace'.  If you want to do further
  733.      replacement you must use `C-x ESC' to restart (*note
  734.      Repetition::.).
  735.  
  736. `ESC'
  737.      to exit without doing any more replacements.
  738.  
  739. `. (Period)'
  740.      to replace this occurrence and then exit.
  741.  
  742. `!'
  743.      to replace all remaining occurrences without asking again.
  744.  
  745. `^'
  746.      to go back to the location of the previous occurrence (or what
  747.      used to be an occurrence), in case you changed it by mistake. 
  748.      This works by popping the mark ring.  Only one `^' in a row is
  749.      allowed, because only one previous replacement location is kept
  750.      during `query-replace'.
  751.  
  752. `C-r'
  753.      to enter a recursive editing level, in case the occurrence needs
  754.      to be edited rather than just replaced with NEWSTRING.  When you
  755.      are done, exit the recursive editing level with `C-M-c' and the
  756.      next occurrence will be displayed.  *Note Recursive Edit::.
  757.  
  758. `C-w'
  759.      to delete the occurrence, and then enter a recursive editing
  760.      level as in `C-r'.  Use the recursive edit to insert text to
  761.      replace the deleted occurrence of STRING.  When done, exit the
  762.      recursive editing level with `C-M-c' and the next occurrence will
  763.      be displayed.
  764.  
  765. `C-l'
  766.      to redisplay the screen and then give another answer.
  767.  
  768. `C-h'
  769.      to display a message summarizing these options, then give another
  770.      answer.
  771.  
  772.    If you type any other character, Emacs exits the `query-replace',
  773. and executes the character as a command.  To restart the
  774. `query-replace', use `C-x ESC', which repeats the `query-replace'
  775. because it used the minibuffer to read its arguments.  *Note C-x ESC:
  776. Repetition.
  777.  
  778. 
  779. File: emacs,  Node: Other Repeating Search,  Prev: Replace,  Up: Search
  780.  
  781. Other Search-and-Loop Commands
  782. ==============================
  783.  
  784.    Here are some other commands that find matches for a regular
  785. expression.  They all operate from point to the end of the buffer.
  786.  
  787. `M-x occur'
  788.      Print each line that follows point and contains a match for the
  789.      specified regexp.  A numeric argument specifies the number of
  790.      context lines to print before and after each matching line; the
  791.      default is none.
  792.  
  793.      The buffer `*Occur*' containing the output serves as a menu for
  794.      finding occurrences in their original context.  Find an occurrence
  795.      as listed in `*Occur*', position point there, and type `C-c C-c';
  796.      this switches to the buffer that was searched and moves point to
  797.      the original of the same occurrence.
  798.  
  799. `M-x list-matching-lines'
  800.      Synonym for `M-x occur'.
  801.  
  802. `M-x count-matches'
  803.      Print the number of matches following point for the specified
  804.      regexp.
  805.  
  806. `M-x delete-non-matching-lines'
  807.      Delete each line that follows point and does not contain a match
  808.      for the specified regexp.
  809.  
  810. `M-x delete-matching-lines'
  811.      Delete each line that follows point and contains a match for the
  812.      specified regexp.
  813.  
  814. 
  815. File: emacs,  Node: Fixit,  Next: Files,  Prev: Search,  Up: Top
  816.  
  817. Commands for Fixing Typos
  818. *************************
  819.  
  820.    This chapter describes commands that are especially useful when you
  821. catch a mistake in your text just after you have made it, or change
  822. your mind while composing text on line.
  823.  
  824. * Menu:
  825.  
  826. * Kill Errors:: Commands to kill a batch of recently entered text.
  827. * Transpose::   Exchanging two characters, words, lines, lists...
  828. * Fixing Case:: Correcting case of last word entered.
  829. * Spelling::    Apply spelling checker to a word, or a whole file.
  830.  
  831. 
  832. File: emacs,  Node: Kill Errors,  Next: Transpose,  Prev: Fixit,  Up: Fixit
  833.  
  834. Killing Your Mistakes
  835. =====================
  836.  
  837. `DEL'
  838.      Delete last character (`delete-backward-char').
  839.  
  840. `M-DEL'
  841.      Kill last word (`backward-kill-word').
  842.  
  843. `C-x DEL'
  844.      Kill to beginning of sentence (`backward-kill-sentence').
  845.  
  846.    The DEL character (`delete-backward-char') is the most important
  847. correction command.  When used among graphic (self-inserting)
  848. characters, it can be thought of as canceling the last character typed.
  849.  
  850.    When your mistake is longer than a couple of characters, it might
  851. be more convenient to use `M-DEL' or `C-x DEL'.  `M-DEL' kills back to
  852. the start of the last word, and `C-x DEL' kills back to the start of
  853. the last sentence.  `C-x DEL' is particularly useful when you are
  854. thinking of what to write as you type it, in case you change your mind
  855. about phrasing.  `M-DEL' and `C-x DEL' save the killed text for `C-y'
  856. and `M-y' to retrieve.  *Note Yanking::.
  857.  
  858.    `M-DEL' is often useful even when you have typed only a few
  859. characters wrong, if you know you are confused in your typing and
  860. aren't sure exactly what you typed.  At such a time, you cannot
  861. correct with DEL except by looking at the screen to see what you did. 
  862. It requires less thought to kill the whole word and start over.
  863.  
  864. 
  865. File: emacs,  Node: Transpose,  Next: Fixing Case,  Prev: Kill Errors,  Up: Fixit
  866.  
  867. Transposing Text
  868. ================
  869.  
  870. `C-t'
  871.      Transpose two characters (`transpose-chars').
  872.  
  873. `M-t'
  874.      Transpose two words (`transpose-words').
  875.  
  876. `C-M-t'
  877.      Transpose two balanced expressions (`transpose-sexps').
  878.  
  879. `C-x C-t'
  880.      Transpose two lines (`transpose-lines').
  881.  
  882.    The common error of transposing two adjacent characters can be fixed
  883. with the `C-t' command (`transpose-chars').  Normally, `C-t'
  884. transposes the two characters on either side of point.  When given at
  885. the end of a line, `C-t' transposes the last two characters on the
  886. line, rather than transposing the last character of the line with the
  887. newline, which would be useless.  If you catch a transposition error
  888. right away, you can fix it with just `C-t'.  If you catch the error
  889. later,  move the cursor back to between the two transposed characters.
  890.  If you transposed a space with the last character of the word before
  891. it, the word motion commands are a good way of getting there. 
  892. Otherwise, a reverse search (`C-r') is often the best way.  *Note
  893. Search::.
  894.  
  895.    `Meta-t' (`transpose-words') transposes the word before point with
  896. the word after point.  It moves point forward over a word, dragging
  897. the word preceding or containing point forward as well.  The
  898. punctuation characters between the words do not move.  For example,
  899. `FOO, BAR' transposes into `BAR, FOO' rather than `BAR FOO,'.
  900.  
  901.    `C-M-t' (`transpose-sexps') is a similar command for transposing
  902. two expressions (*note Lists::.), and `C-x C-t' (`transpose-lines')
  903. exchanges lines.  It works like `M-t' but in determins the division of
  904. the text into syntactic units differently.
  905.  
  906.    A numeric argument to a transpose command serves as a repeat count:
  907. it tells the transpose command to move the character (word, sexp,
  908. line) before or containing point across several other characters
  909. (words, sexps, lines).  For example, `C-u 3 C-t' moves the character
  910. before point forward across three other characters.  This is
  911. equivalent to repeating `C-t' three times.  `C-u - 4 M-t' moves the
  912. word before point backward across four words.  `C-u - C-M-t' would
  913. cancel the effect of plain `C-M-t'.
  914.  
  915.    A numeric argument of zero transposes the character (word, sexp,
  916. line) ending after point with the one ending after the mark (otherwise
  917. a command with a repeat count of zero would do nothing).
  918.  
  919. 
  920. File: emacs,  Node: Fixing Case,  Next: Spelling,  Prev: Transpose,  Up: Fixit
  921.  
  922. Case Conversion
  923. ===============
  924.  
  925. `M-- M-l'
  926.      Convert last word to lower case.  Note `Meta--' is Meta-minus.
  927.  
  928. `M-- M-u'
  929.      Convert last word to all upper case.
  930.  
  931. `M-- M-c'
  932.      Convert last word to lower case with capital initial.
  933.  
  934.    A  common error is to type words in the wrong case.  Because of
  935. this, the word case-conversion commands `M-l', `M-u' and `M-c' do not
  936. move the cursor when used with a negative argument.  As soon as you
  937. see you have mistyped the last word, you can simply case-convert it
  938. and continue typing.  *Note Case::.
  939.  
  940. 
  941. File: emacs,  Node: Spelling,  Prev: Fixing Case,  Up: Fixit
  942.  
  943. Checking and Correcting Spelling
  944. ================================
  945.  
  946. `M-$'
  947.      Check and correct spelling of word (`spell-word').
  948.  
  949. `M-x spell-buffer'
  950.      Check and correct spelling of each word in the buffer.
  951.  
  952. `M-x spell-region'
  953.      Check and correct spelling of each word in the region.
  954.  
  955. `M-x spell-string'
  956.      Check spelling of specified word.
  957.  
  958.    To check the spelling of the word before point, and optionally
  959. correct it, use the command `M-$' (`spell-word').  This command runs an
  960. inferior process containing the `spell' program to see whether the
  961. word is correct English.  If it is not, it asks you to edit the word
  962. (in the minibuffer) into a corrected spelling, and then performs a
  963. `query-replace' to substitute the corrected spelling for the old one
  964. throughout the buffer.
  965.  
  966.    If you exit the minibuffer without altering the original spelling,
  967. it means you do not want to do anything to that word.  In that case,
  968. the `query-replace' is not done.
  969.  
  970.    `M-x spell-buffer' checks each word in the buffer the same way that
  971. `spell-word' does, doing a `query-replace' for every incorrect word if
  972. appropriate.
  973.  
  974.    `M-x spell-region' is similar to `spell-buffer' but operates only
  975. on the region, not the entire buffer.
  976.  
  977.    `M-x spell-string' reads a string as an argument and checks whether
  978. that is a correctly spelled English word.  It prints a message giving
  979. the answer in the echo area.
  980.  
  981. 
  982. File: emacs,  Node: Files,  Next: Buffers,  Prev: Fixit,  Up: Top
  983.  
  984. File Handling
  985. *************
  986.  
  987.    The basic unit of stored data in Unix is the "file".  To edit a
  988. file, you must tell Emacs to examine the file and prepare a buffer
  989. containing a copy of the file's text.  This is called "visiting" the
  990. file.  Editing commands apply directly to text in the buffer; that is,
  991. to the copy inside Emacs.  Your changes appear in the file itself only
  992. when you "save" the buffer back into the file.
  993.  
  994.    In addition to visiting and saving files, Emacs can delete, copy,
  995. rename, and append to files, and operate on file directories.
  996.  
  997. * Menu:
  998.  
  999. * File Names::   How to type and edit file name arguments.
  1000. * Visiting::     Visiting a file prepares Emacs to edit the file.
  1001. * Saving::       Saving makes your changes permanent.
  1002. * Reverting::    Reverting cancels all the changes not saved.
  1003. * Auto Save::    Auto Save periodically protects against loss of data.
  1004. * ListDir::      Listing the contents of a file directory.
  1005. * Dired::        "Editing" a directory to delete, rename, etc.
  1006.                   the files in it.
  1007. * Misc File Ops:: Other things you can do on files.
  1008.  
  1009. 
  1010. File: emacs,  Node: File Names,  Next: Visiting,  Prev: Files,  Up: Files
  1011.  
  1012. File Names
  1013. ==========
  1014.  
  1015.    Most Emacs commands that operate on a file require you to specify
  1016. the file name.  (Saving and reverting are exceptions; the buffer knows
  1017. which file name to use for them.)  File names are specified in the
  1018. minibuffer (*note Minibuffer::.).  "Completion" is available, to make
  1019. it easier to specify long file names.  *Note Completion::.
  1020.  
  1021.    There is always a "default file name" which is used if you enter an
  1022. empty argument by typing just RET.  Normally the default file name is
  1023. the name of the file visited in the current buffer; this makes it easy
  1024. to operate on that file with any of the Emacs file commands.
  1025.  
  1026.    Each buffer has a default directory, normally the same as the
  1027. directory of the file visited in that buffer.  When Emacs reads a file
  1028. name, the default directory is used if you do not specify a directory. 
  1029. If you specify a directory in a relative fashion, with a name that does
  1030. not start with a slash, it is interpreted with respect to the default
  1031. directory.  The default directory of the current buffer is kept in the
  1032. variable `default-directory', which has a separate value in every
  1033. buffer.  The value of the variable should end with a slash.
  1034.  
  1035.    For example, if the default file name is `/u/rms/gnu/gnu.tasks' then
  1036. the default directory is `/u/rms/gnu/'.  If you type just `foo', which
  1037. does not specify a directory, it is short for `/u/rms/gnu/foo'. 
  1038. `../.login' would stand for `/u/rms/.login'.  `new/foo' would stand
  1039. for the filename `/u/rms/gnu/new/foo'.
  1040.  
  1041.    The variable `default-directory-alist' takes an alist of major
  1042. modes and their opinions on `default-directory' as a Lisp expression
  1043. to evaluate.  A resulting value of `nil' is ignored in favor of
  1044. `default-directory'.
  1045.  
  1046.    You can create a new directory with the function `make-directory',
  1047. which takes as an argument a file name string. The current directory is
  1048. displayed in the minibuffer when the function is called; you can delete
  1049. the old directory name and supply a new directory name. For example, if
  1050. the current directory is `/u/rms/gnu', you can delete `gnu' and type
  1051. `oryx' and RET to create `/u/rms/oryx'.  Removing a directory is
  1052. similar to creating one.  To remove a directory, use
  1053. `remove-directory'; it takes one argument a file name string.
  1054.  
  1055.    The command `M-x pwd' prints the current buffer's default directory,
  1056. and the command `M-x cd' sets it (to a value read using the
  1057. minibuffer).  A buffer's default directory changes only when the `cd'
  1058. command is used.  A file-visiting buffer's default directory is
  1059. initialized to the directory of the file that is visited there.  If a
  1060. buffer is created with `C-x b', its default directory is copied from
  1061. that of the buffer that was current at the time.
  1062.  
  1063.    The default directory name actually appears in the minibuffer when
  1064. the minibuffer becomes active to read a file name.  This serves two
  1065. purposes: it shows you what the default is, so that you can type a
  1066. relative file name and know with certainty what it will mean, and it
  1067. allows you to edit the default to specify a different directory.  To
  1068. inhibit the insertion of the default directory, set the variable
  1069. `insert-default-directory' to `nil'.
  1070.  
  1071.    Note that it is legitimate to type an absolute file name after you
  1072. enter the minibuffer, ignoring the presence of the default directory
  1073. name.  The final minibuffer contents may look invalid, but that is not
  1074. so.  *Note Minibuffer File::.
  1075.  
  1076.    `$' in a file name is used to substitute environment variables.  For
  1077. example, if you have used the shell command `setenv FOO rms/hacks' to
  1078. set up an environment variable named `FOO', then you can use
  1079. `/u/$FOO/test.c' or `/u/${FOO}/test.c' as an abbreviation for
  1080. `/u/rms/hacks/test.c'.  The environment variable name consists of all
  1081. the alphanumeric characters after the `$'; alternatively, it may be
  1082. enclosed in braces after the `$'.  Note that the `setenv' command
  1083. affects Emacs only if done before Emacs is started.
  1084.  
  1085.    To access a file with `$' in its name, type `$$'.  This pair is
  1086. converted to a single `$' at the same time variable substitution is
  1087. performed for single `$'.  The Lisp function that performs the
  1088. substitution is called `substitute-in-file-name'.  The substitution is
  1089. performed only on filenames read as such using the minibuffer.
  1090.  
  1091.